﻿using NORM.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevelopAssistant.Service
{
    public class CreateOrReplaceObject
    {
        public static string ToSnippetCode(string ObjectName, DataBaseServer DatabaseServer)
        {
            StringPlus sp = new StringPlus();

            string ProcedureName = "sp_helptext";
            System.Data.Common.DbParameter[] dbParameters = null;
            DataTable dt = new DataTable();

            using (var db = Utility.GetAdohelper(DatabaseServer))
            {
                switch (DatabaseServer.ProviderName)
                {
                    case "System.Data.Sql":
                    case "System.Data.SQL":
                        dbParameters = new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@objname", ObjectName) };
                        dt = db.GetDataSet(CommandType.StoredProcedure, ProcedureName, dbParameters).Tables[0];
                        break;
                }       
               
                foreach (DataRow dr in dt.Rows)
                {
                    sp.Append("" + dr["Text"] + "");
                }

            } 

            return sp.Value;
        }       
    }
}
